package com.leyou.order.config;

import com.github.wxpay.sdk.WXPay;
import com.github.wxpay.sdk.WXPayConfigImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 虎哥
 */
@Slf4j
@Configuration
public class WxConfig {

    @Bean
    @ConfigurationProperties(prefix = "ly.pay.wx")
    public WXPayConfigImpl payConfig(){
        return new WXPayConfigImpl();
    }

    @Bean
    public WXPay wxPay(WXPayConfigImpl payConfig){
        try {
            return new WXPay(payConfig);
        } catch (Exception e) {
            log.error("构建微信工具类失败！原因：{}", e.getMessage());
            throw new RuntimeException(e);
        }
    }
}
